@isTest
private class SelectListComponentTestWrapperCtrlrTest {

    static testMethod void myUnitTest() {
        SelectListComponentTestWrapperController controller = getController();
    	//This is more about making sure my test code has worked...
    	system.assert(controller.ListComponent1Data != null);
    	system.assert(controller.ListComponent2Data != null);
    	
    	//Select some options
    	//To select options, we need to pass a list of values to the controller's selected items and then call the appropriate method
    	controller.ListComponent1Controller.SelectedAvailableOption = new list<string>{controller.ListComponent1Data[0].getValue(), controller.ListComponent1Data[2].getValue()};
    	controller.ListComponent1Controller.Add();

    	system.assertEquals(2, controller.ListComponent1Controller.ChosenOptions.size());

    	controller.ListComponent2Controller.SelectedAvailableOption = new list<string>{controller.ListComponent2Data[0].getValue(), controller.ListComponent2Data[3].getValue(), controller.ListComponent2Data[5].getValue(), controller.ListComponent2Data[7].getValue()};
    	controller.ListComponent2Controller.Add();

    	system.assertEquals(4, controller.ListComponent2Controller.ChosenOptions.size());

    	controller.ListComponent2Controller.SelectedChosenOption = new list<string>{controller.ListComponent2Data[3].getValue(), controller.ListComponent2Data[7].getValue()};
    	controller.ListComponent2Controller.Remove();

    	system.assertEquals(2, controller.ListComponent2Controller.ChosenOptions.size());
    }
    
	private static SelectListComponentTestWrapperController getController(){
        //The data in the picklists is populated when the PAGE loads.  
        //Simulate this by populating the select lists after instantiating the controller;
		SelectListComponentTestWrapperController controller = new SelectListComponentTestWrapperController();
    	
    	//The Fake items should be ignored because they're not active
    	system.assertEquals(6, controller.ListComponent1Data.size());
    	system.assertEquals(9, controller.ListComponent2Data.size());
    	
    	//Populate the Select List components
    	//Build the selectlist component 
    	SelectListComponentController selectList1 = getSelectList(controller, 'SelectList1', controller.ListComponent1Data);
    	controller.setComponentControllerMap('SelectList1', selectList1); //The map gets searched when the component is called
//    	controller.setComponentController(selectList1);
    	controller.ListComponent1Controller = selectList1;
    	
    	SelectListComponentController selectList2 = getSelectList(controller, 'SelectList2', controller.ListComponent2Data);
    	controller.setComponentControllerMap('SelectList2', selectList2);
    	controller.ListComponent2Controller = selectList2;

		return controller;
	}
	
	private static SelectListComponentController getSelectList(PageControllerBase pageController, string Key, Selectoption[] ListData){
    	SelectListComponentController selectListCtrlr = new SelectListComponentController();
    	selectListCtrlr.ListOptions = ListData;
    	selectListCtrlr.Key = Key; //This is how the component is uniquely identified
    	selectListCtrlr.Rows = 5;
    	selectListCtrlr.ListWidth = 200;
    	selectListCtrlr.pageController = pageController; //The controller class extends pageController

    	return selectListCtrlr;
	}
}